package com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.dao.Impl;

import com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.dao.SearchDao;
import com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.entity.SearchEntity;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SearchDaoImpl implements SearchDao {
    public List<SearchEntity> queryInformation(String name) throws Exception {




        Connection connection = DBUtils.getCon();
        List<SearchEntity> InformationList = new ArrayList<>();
        String sql = "select leave_date,leave_class,adjust_date,adjust_class,reason from adjust where name =?";
        //String sql = "select leave_date,leave_class,adjust_date,adjust_class,reason from adjust where  name = name1 ";
        //String sql = "select leave_date, leave_class, adjust_date,adjust_class,reason  from adjust where name ='徐天赋'";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setString(1,name);

        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {

            SearchEntity searchEntity = new SearchEntity();

            searchEntity.setLeave_date(resultSet.getDate("leave_date"));
            searchEntity.setLeave_class(resultSet.getString("leave_class"));
            searchEntity.setAdjust_date(resultSet.getDate("adjust_date"));
            searchEntity.setAdjust_class(resultSet.getString("adjust_class"));
            searchEntity.setReason(resultSet.getString("reason"));


            String adjust_class;
            InformationList.add(searchEntity);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return InformationList;
    }
}
